package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dto.CategoryResponse;
import com.cskaoyan.shopping.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author llf
 * @Date 2022/6/18 18:18
 */
@RestController
public class ShoppingCategoryController {
    @Autowired
    ICategoryService iCategoryService;

    @GetMapping("/shopping/categories")
    public ResponseData shoppingCategory(String sort){
        if ("".equals(sort)){
            sort="1";
        }
        CategoryResponse categoryResponse=iCategoryService.categoryPage(sort);
        if (ShoppingRetCode.SUCCESS.getCode().equals(categoryResponse.getCode())) {
            // 执行成功，直接返回前端需要的数据
            return new ResponseUtil().setData(categoryResponse.getCategoryDtos());
        }
        // 调用失败
        return new ResponseUtil().setErrorMsg(categoryResponse.getMsg());
    }
}
